package com.blb.service.impl;

import com.blb.mapper.UserMapper;
import com.blb.pojo.User;
import com.blb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userDAO;

    @Override
    public User login(String username, String password) {
        try {
            User user = userDAO.selectUserByUsername(username);
            if(!password.equals(user.getPassword())){
                throw new RuntimeException("密码错误");
            }
            return user;
        }catch (EmptyResultDataAccessException ex){
            throw new RuntimeException("用户名不存在");
        }
    }
}
